package com.grape.service.take_delivery.impl;


import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.grape.dao.take_delivery.PromotionRepository;
import com.grape.domain.base.PageBean;
import com.grape.domain.take_delivery.Promotion;
import com.grape.service.take_delivery.PromotionService;

@Service
@Transactional
public class PromotionServiceImpl implements PromotionService{

	@Autowired PromotionRepository pr;
	
	@Override
	public void save(Promotion model) {
		pr.save(model);
	}

	@Override
	public Page<Promotion> findAll(Pageable pageable) {
		return pr.findAll(pageable);
	}

	@Override
	public PageBean<Promotion> pageQuery(String page, String rows) {
		System.out.println("促销分页方法触发>>>>>>>>>>>>>>>>");
		
		Integer page1 = Integer.parseInt(page)-1;
		Integer rows1 = Integer.parseInt(rows);
		PageRequest pageRequest = new PageRequest(page1,rows1);
		
		Page<Promotion> findAll = pr.findAll(pageRequest);
		
		PageBean<Promotion> pp = new PageBean<>();
		pp.setPageData(findAll.getContent());
		pp.setTotalCount(findAll.getTotalElements());
		
		return pp;
	}

	@Override
	public Promotion findOne(String id) {
		return pr.findOne(Integer.parseInt(id));
	}

	@Override
	public void updateStatus(Date date) {
		pr.updateStatus(date);
	}


}
